﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;

namespace Surfium
{

    public partial class MyPopUp : SurfaceUserControl
    {

        public static readonly RoutedEvent TextChangedEvent = EventManager.RegisterRoutedEvent(
          "TextChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyPopUp));

        public event RoutedEventHandler TextChanged
        {
            add { AddHandler(TextChangedEvent, value); }
            remove { RemoveHandler(TextChangedEvent, value); }
        }

        public void RaiseTextChangedEvent()
        {
            RoutedEventArgs newEventArgs = new RoutedEventArgs(MyPopUp.TextChangedEvent);
            RaiseEvent(newEventArgs);
        }

        private int componentId;
        public SurfaceTextBox InputText
        {
            get { return inputText; }
        }

        public int ComponentId
        {
            get { return componentId; }
            set { componentId = value; }
        }
        public MyPopUp()
        {
            InitializeComponent();
            inputText.TextChanged += new TextChangedEventHandler(inputText_TextChanged);
        }

        public void set(int componentId, FormType type, string label)
        {
            inputText.Text = label;
            this.componentId = componentId;
        }

        private void inputText_TextChanged(object sender, TextChangedEventArgs e)
        {
            RaiseTextChangedEvent();
        }

        private void inputText_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                this.Visibility = System.Windows.Visibility.Hidden;
            }
        }

        public void focus()
        {
            if (!inputText.IsKeyboardFocusWithin)
            {
                inputText.Focus();

            }
            inputText.SelectAll();
        }




    }
}
